package com.gxgeek.javabasic.reflect.autowired;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
 * @author gaoxing
 * @create 2017-10-18 上午11:12
 */
public class TestAnnotation {
    @TestAnno
    private String a;

    @Override
    public String toString() {
        return "TestAnnotation{" +
                "a='" + a + '\'' +
                '}';
    }

    public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException {
        TestAnnotation ta=new TestAnnotation();
        Field[] fs=TestAnnotation.class.getDeclaredFields();
        for(int i=0;i<fs.length;i++){
            if(fs[i].isAnnotationPresent(TestAnno.class)){
                System.out.println(!Modifier.isPublic(fs[i].getModifiers()));
                System.out.println(!Modifier.isPublic(fs[i].getDeclaringClass().getModifiers()));
                System.out.println(Modifier.isFinal(fs[i].getModifiers()));
                System.out.println(!fs[i].isAccessible());
                System.out.println((!Modifier.isPublic(fs[i].getModifiers()) ||
                !Modifier.isPublic(fs[i].getDeclaringClass().getModifiers()) ||
                        Modifier.isFinal(fs[i].getModifiers())) && !fs[i].isAccessible());

                    fs[i].setAccessible(true);
                fs[i].set(ta, "你好");
            }
        }
        System.out.println(ta);
    }

}
